﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using SensorNetworkUI;
using CenterSpace.NMath.Stats;
using CenterSpace.NMath.Core;
namespace WebAccess
{
    public abstract class ProbabilityMethods:StatEngine
    {
        public abstract double CalculateProbability(HashSet<SensorStructure> sensors,double temp);
        protected ProbabilityMethods()
        {


        }
        public static ProbabilityMethods GetInstance(String Dist)
        {
            switch (Dist)
            {
                case "Normal":
                    return new Normal();


                default:
                    throw new NotImplementedException();
            }


        }
    }

    public class Normal : ProbabilityMethods
    {

        public override double CalculateProbability(HashSet<SensorStructure> sensors, double temp)
        {
            double[] vals = SetToArray(sensors);
            double mean = StatsFunctions.Mean(vals);
            double variance = StatsFunctions.Variance(vals);
            NormalDistribution norm = new NormalDistribution(mean, variance);
            double upper = norm.CDF(temp + 1);
            double lower = norm.CDF(temp - 1);
            return Math.Abs((upper - lower));
        }
    }

    public class Uniform : ProbabilityMethods
    {
        public override double CalculateProbability(HashSet<SensorStructure> sensors, double temp)
        {
            double[] vals = SetToArray(sensors);
            double min = StatsFunctions.MinValue(vals);
            double max = StatsFunctions.MaxValue(vals);
            UniformDistribution ufd = new UniformDistribution(min, max);
            double upper = ufd.CDF(temp + 1);
            double lower = ufd.CDF(temp - 1);
            return Math.Abs((upper - lower));
        }


    }

}